package org.hackday.evetteam;

import java.util.StringTokenizer;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import  android.widget.AdapterView;

import android.widget.TextView;

public class EventViewActivity extends ListActivity {
	
	EventViewActivity ev;
	@Override
	public void onCreate(Bundle viewEventList){
		super.onCreate(viewEventList);
		Bundle extras = getIntent().getExtras();
        String i1 = extras.getString( "Response" );
        
String text = i1;
		ev=this;

	StringTokenizer st = new StringTokenizer(text,",");	

	String [] newevents;
	newevents=new String[20];
	int count=0;
	while(st.hasMoreTokens()) {
		
		newevents[count++]=st.nextToken();
		//System.out.println(newevents[count]);
		
	}
	

    String[] results = text.split( ",\\s*" ); // split on commas

	
		int duration = Toast.LENGTH_SHORT;
	 Context context; 
		context = getApplicationContext();
		Toast toast = Toast.makeText(context, text, duration);
		//toast.setGravity(Gravity.CENTER, 0, 0);
		//toast.show();
		//setListAdapter(new ArrayAdapter<String>(this, R.layout.event_view, newevents));
		setListAdapter(new ArrayAdapter<String>(this, R.layout.event_view, results));
		ListView eventlv = getListView();
		
		eventlv.setTextFilterEnabled(true);
		
		eventlv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
		    @Override
		    public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
		       // onListItemClick(v,pos,id);
		    	//Toast.makeText(getApplicationContext(), ((TextView) v).getText(), Toast.LENGTH_SHORT).show();
		    	
		    	Intent i = new Intent(ev, seeeventdetails.class);
                
                i.putExtra("eventname",((TextView) v).getText());
                
                
                startActivity(i);
		       
		    }
		    
		    protected void onListItemClick(View v, int pos, long id) {
	           // Log.i(TAG, "onListItemClick id=" + id);
	        }
		});
		/*
		eventlv.setOnItemClickListener( new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
			}
		});*/
		
	}
	
	
	void resolveIntent(Intent intent) {
		Bundle extras = intent.getExtras();

		String response = extras != null ? extras.getString("Response") : null;
		
		String text = response;
		
		int duration = Toast.LENGTH_SHORT;
	 Context context; 
		context = getApplicationContext();
		Toast toast = Toast.makeText(context, text, duration);
		//toast.setGravity(Gravity.CENTER, 0, 0);
		toast.show();
		

	}
	
	static final String[] EVENTS = new String [] {
		"Hackday Meeting", "All Hands Meeting", "TRON Party", "Interview"
	};
	

}
